package Introspector;

import Car.Car.Car;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;


public class Introspector {
    public static void setProperty(Car car,String name,String value){
        PropertyDescriptor propsDesc = null;
        try {
            propsDesc = new PropertyDescriptor(name, Car.class);
            Method writeMethod = propsDesc.getWriteMethod();
            writeMethod.invoke(car,value);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static void setProperty(Car car,String name,double value){
        PropertyDescriptor propsDesc = null;
        try {
            propsDesc = new PropertyDescriptor(name, Car.class);
            Method writeMethod = propsDesc.getWriteMethod();
            writeMethod.invoke(car,value);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static void setProperty(Car car,String name,int value){
        PropertyDescriptor propsDesc = null;
        try {
            propsDesc = new PropertyDescriptor(name, Car.class);
            Method writeMethod = propsDesc.getWriteMethod();
            writeMethod.invoke(car,value);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static String getIntProperty(Car car,String name){
        PropertyDescriptor propsDesc = null;
        String value = null;
        try {
            propsDesc = new PropertyDescriptor(name, Car.class);
            Method readMethod = propsDesc.getReadMethod();
            Object invoke = readMethod.invoke(car);
            value = String.valueOf(invoke);
        }catch (Exception e){
            e.printStackTrace();
        }
        return value;
    }
}
